export default {
	data() {
		return {
			orderList: [], // 订单列表
			page: 1, // 页码
			pageSize: 10, // 页面大小
			noMore: false, // 没有更多了
		}
	},
	onLoad() {
		const onLogin = () => {
			this.getOrderList(); // 获取订单
		}
		this.$util.checkLogin(this, onLogin);
	},
	onReachBottom() {
		if (this.noMore) return false;
		this.page++;
		this.getOrderList();
	},
	methods: {
		JumpDetails(item) {
			uni.navigateTo({
					 url: `/pages/mine/orderDetails/orderDetails/orderDetails`,
					 success: (res) => {
				  		  res.eventChannel.emit('event', { data: item })
					 }
				});
			// uni.navigateTo({
			// 	url:`/pages/mine/orderDetails/orderDetails/orderDetails?item=${encodeURIComponent(JSON.stringify(item))}`
			// })
			
		},
		back() {
			uni.navigateBack({
				delta: 1
			})
		},
		// 报修
		fault: function() {
			if (this.$store.state.deviceId) {
				uni.navigateTo({
					url: "/pages/fault/fault"
				})
				return;
			}
			uni.showModal({
				title: '提示',
				content: '请扫描设备上的二维码，以便我们知道您身边的设备',
				showCancel: true,
				cancelText: '取消',
				confirmText: '扫码',
				success: res => {
					if (!res.confirm) {
						return;
					}
					uni.scanCode({
						onlyFromCamera: false,
						success: (res) => {
							this.$util.extractUri(this, res.result)
							//this.getPageData();
							this.fault();
							this.isManage();
						},
						complete: (res) => {
							console.log(res)
						}
					});
				}
			});
		},
		// 点击我的
		mine: function() {
			uni.navigateTo({
				url: "/pages/mine/mine"
			})
		},
		IndexJump() {
			uni.navigateTo({
				url: "/pages/index/index"
			})
		},
		// 扫码获取数据
		scanToGetData: function() {
			uni.scanCode({
				onlyFromCamera: false,
				success: (res) => {
					this.$util.extractUri(this, res.result)
					console.log('扫码')
					const onLogin = () => {
						//this.getPageData();
						this.isManage();
						this.getBanners()
					}
					this.$util.checkLogin(this, onLogin);
				},
				complete: (res) => {
					console.log(res)
				}
			});
		},
		// 查询是否上货员
		isManage: function() {
			let data = {
				userId: this.$store.state.userInfo.userId,
				deviceId: this.$store.state.deviceId,
			}
			this.$request(this.$api.IsManage, data, "POST", true, "application/x-www-form-urlencoded").then(res => {
				let data = JSON.parse(res.data)

				if (data && data.courier == "true") {
					this.$store.state.isManage = true;
				} else {
					this.$store.state.isManage = false;
				}
			});
		},
		getBanners() {
			this.$request(this.$api.getBanners, {
				deviceId: this.$store.state.deviceId
			}).then(res => {
				if (res.code == 200) {

					this.imgUrls = res.result
				}
			})
		},

		// 申请退款
		refund: function(orderId) {
			uni.navigateTo({
				url: "/pages/mine/order/refundV2/refundV2?orderId=" + orderId
			})
		},

		// 获取订单列表
		getOrderList: function() {
			let data = {
				deviceId: '', //测试，后面删除
				orderId: "", // 空值查全部，非零查准确订单
				userId: this.$store.state.userInfo.userId,
				pageNo: this.page, // 页码
				pageSize: this.pageSize, // 页面大小
			}
			this.$request(this.$api.GetOrderData, data, "GET").then(res => {

				if (res.code == 200) {
					res.result = res.result || [];
					//console.log(res.result)
					res.result.records.forEach((item, index) => {
						// if(item.orderDetail === "") {}else {
						// 	item.orderDetail= JSON.parse(item.orderDetail);
						// }
						// item.orderDetail= JSON.parse(item.orderDetail);
						this.orderList.push(item)
					})
					if (res.result.records.length < res.result.size) {
						this.noMore = true;
					}
				} else {
					// uni.showToast({
					// 	title: res.returnMessage,
					// 	icon:"none"
					// });
				}
			})
		},
	}
}